package com.zjl.hiring.company.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zjl.hiring.common.DBObject;
import com.zjl.hiring.common.util.DBUtil;
import com.zjl.hiring.company.entity.CompanyEntity;


public class CompanyDao {
	/**
	 * 登录
	 * @param code
	 * @param password
	 * @return
	 */
	public CompanyEntity login(String code, String password) {
		CompanyEntity company = null;
		String sql = "SELECT * FROM company WHERE code=? AND password=?";
		DBObject dbObject = null;
		try {
			dbObject = DBUtil.executeQuery(sql, code,password);
			ResultSet resultSet = dbObject.getResultSet();
			while(resultSet.next()) {
				company = new CompanyEntity();
				company.setId(resultSet.getInt("id"));
				company.setName(resultSet.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(dbObject);
		}
		return company;
	}
	/**
	 * 注册
	 * @param talent
	 * @return
	 */
	public int register(CompanyEntity company) {
		int row = 0;
		String sql = "INSERT INTO company VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		try {
			List<Object> paramList = new ArrayList<>();
			paramList.add(company.getCode());
			paramList.add(company.getPassword());
			paramList.add(company.getName());
			paramList.add(company.getEmail());
			paramList.add(company.getPhone());
			paramList.add(company.getLinkman());
			paramList.add(company.getAddress());
			paramList.add(company.getNumbers());
			paramList.add(company.getSlogan());
			row = DBUtil.executeUpdate(sql, paramList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return row;
	}
	
}
